package com.bstek.uflo.samplecenter;

import java.sql.SQLException;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;

import com.bstek.uflo.env.EnvironmentProvider;

@Configuration
@ComponentScan(basePackages = {"com.bstek.uflo.samplecenter"})
//@EntityScan(value = "com.bstek.uflo.model*")
//@ImportResource("classpath:context-mysql.xml")
@ImportResource("classpath:uflo-console-context.xml")
@Component
public class UfloEnvironment implements EnvironmentProvider {
	public UfloEnvironment() throws SQLException {
		System.out.println("uflo env init...");
//		System.out.println("数据源>>>>>>" + datasource.getClass());
//	    Connection connection = datasource.getConnection();
//	    System.out.println("连接>>>>>>>>>" + connection);
//	    System.out.println("连接地址>>>>>" + connection.getMetaData().getURL());
	}

	public String getLoginUser() {
//		return ContextHolder.getLoginUserName();
		return "user1";
	}

	@Override
	public String getCategoryId() {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Resource
	private DataSource dataSource;
	
	@Resource
	private PlatformTransactionManager transactionManager;
	
	@Override
	public DataSource getDataSource() {
		return dataSource;
	}

	@Override
	public PlatformTransactionManager getPlatformTransactionManager() {
		return transactionManager;
	}

}